<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<vertical-section-layout section-title='{{"views.feed-additional-properties.Properties" | translate}}' on-save-edit="vm.onSave()" on-edit="vm.onEdit()" on-cancel-edit="vm.onCancel()" allow-edit="vm.allowEdit"
                         editable="vm.editableSection" keep-editable-after-save="true" is-valid="vm.isValid">

    <readonly-section>
        <div layout="column">
            <div layout="row" class="feed-property versions-{{vm.diff('/dataOwner')}}">
                <span flex="25" class="property-name"> {{"views.feed-additional-properties.DO" | translate}} </span>

                <div flex>
                    {{vm.model.dataOwner}}
                </div>
                <div flex ng-if="vm.versions">
                    {{vm.versionFeedModel.dataOwner}}
                </div>
            </div>
            <div layout="row" class="feed-property versions-{{vm.diffCollection('/tags')}}">
                <span flex="25" class="property-name"> {{"views.feed-additional-properties.Tags" | translate}} </span>

                <div flex>
                    {{vm.model.tags | join: ',':'name'}}
                </div>
                <div flex ng-if="vm.versions">
                    {{vm.versionFeedModel.tags | join: ',':'name'}}
                </div>
            </div>
            <div layout="row" class="feed-property" ng-if="vm.securityGroupsEnabled == true">
                <span flex="25" class="property-name">Hadoop Security Groups</span>

                <div flex>
                    {{vm.model.securityGroups | join: ',':'name'}}
                </div>
                <div flex ng-if="vm.versions">
                    {{vm.versionFeedModel.securityGroups | join: ',':'name'}}
                </div>
            </div>

            <thinkbig-property-list
                ng-if="!vm.versions"
                properties="vm.model.userProperties"></thinkbig-property-list>

            <div ng-if="vm.versions" layout="row" ng-repeat="(propIdx, property) in vm.userProperties" class="feed-property versions-{{property.op}}">
                <div ng-if="property.current.locked" layout="column" flex="25" class="property-name">
                    <span>{{property.displayName}}</span>
                    <span class="hint">{{property.description}}</span>
                </div>
                <span ng-if="!property.current.locked" flex="25" class="property-name">{{property.systemName}}</span>

                <div flex>
                    {{property.current.value}}
                </div>
                <div flex>
                    {{property.versioned.value}}
                </div>
            </div>

        </div>
    </readonly-section>

    <editable-section>
        <md-input-container class="md-block" flex-gt-sm>
            <label> {{"views.feed-additional-properties.DO" | translate}} </label>
            <input ng-model="vm.editModel.dataOwner">
        </md-input-container>

        <md-input-container class="md-block layout-padding-top-bottom flex-gt-sm" flex-gt-sm="" style="">
            <label class="label-small md-container-ignore"> {{"views.feed-additional-properties.Tags" | translate}} </label>
            <md-chips ng-model="vm.editModel.tags" md-autocomplete-snap md-transform-chip="vm.transformChip($chip)" md-require-match="false">
                <md-autocomplete md-selected-item="vm.tagChips.selectedItem" md-search-text="vm.tagChips.searchText" md-items="item in vm.feedTagService.querySearch(vm.tagChips.searchText)"
                        md-item-text="item.name" placeholder='{{"views.feed-additional-properties.AaT" | translate}}'>
                    <span md-highlight-text="vm.tagChips.searchText">{{item.name}}</span>
                </md-autocomplete>
                <md-chip-template>
                    <span>
                        <strong>{{$chip.name}}</strong>
                    </span>
                </md-chip-template>
            </md-chips>
            <span class="hint">Type in a tag and press enter</span>
        </md-input-container>

        <md-input-container class="md-block layout-padding-top-bottom flex-gt-sm condensed" flex-gt-sm="" style="" ng-if="vm.securityGroupsEnabled == true">
            <label class="label-small md-container-ignore">Hadoop Security Groups</label>
            <md-chips ng-model="vm.editModel.securityGroups" md-autocomplete-snap
                      md-transform-chip="vm.transformChip($chip)"
                      md-require-match="true" class="layout-padding-top-bottom">
                <md-autocomplete
                    md-min-length="0"
                    md-selected-item="vm.securityGroupChips.selectedItem"
                    md-search-text="vm.securityGroupChips.searchText"
                    md-items="item in vm.feedSecurityGroups.querySearch(vm.securityGroupChips.searchText)"
                    md-item-text="item.name"
                    placeholder="Add a Hadoop Security Group">
                    <span md-highlight-text="vm.securityGroupChips.searchText">{{item.name}}</span>
                </md-autocomplete>
                <md-chip-template>
                            <span>
                              <strong>{{$chip.name}}</strong>
                            </span>
                </md-chip-template>
            </md-chips>
        </md-input-container>

        <thinkbig-property-list-editor properties="vm.editModel.userProperties" is-valid="vm.isValid"></thinkbig-property-list-editor>
    </editable-section>
</vertical-section-layout>
